package com.dragon.wangyiwork.repository;

import com.dragon.wangyiwork.entity.Commodity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface CommodityRepository extends JpaRepository<Commodity,Integer> {

    public List<Commodity> findCommoditiesByHasBuy(Integer hasBuy);

    @Modifying
    @Query(value = "update commodity c set c.hasBuy = ?1,c.cartCount = ?2 where c.id = ?3")
    public int updateCommodityHasBuyToCart(Integer hasBuy,Integer cartCount,Integer commodityId);

    @Modifying
    @Query(value = "update commodity c set c.title = ?1,c.summary = ?2,c.pic = ?3,c.text = ?4,c.price = ?5 where c.id = ?6")
    public int updateCommodityPublic(String title,String summary,String pic,String text,Float price,Integer commodityId);

    @Modifying
    @Query(value = "update commodity c set c.hasBuy = ?1,c.buyPrice = ?2,c.count = ?3,c.buyDate = ?4 where c.id = ?5")
    public int updateCommodityBuy(Integer hasBuy, Float buyPrice, Integer buyCount, Date now, Integer commodityId);


}
